<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="9" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span style="font-size:18px;font-weight: bold;">商家信息</span>
          </div>
          <div>
            <div class="text-center">
              <image-upload :limit="1" :value="user.image" @input="uploadAvatar"></image-upload>
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" style="margin-right:10px;font-size: 16px;"/>
                <span style="font-size:14px;">商家名称</span>
                <div class="pull-right">{{ user.name }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" style="margin-right:10px;font-size: 16px;"/>
                <span style="font-size:14px;">商家手机号码</span>
                <div class="pull-right">{{ user.phone }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" style="margin-right:10px;font-size: 16px;"/>
                <span style="font-size:14px;">营业时间</span>
                <div class="pull-right">{{ user.beginTime }} - {{user.endTime}}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" style="margin-right:10px;font-size: 16px;"/>
                <span style="font-size:14px;">商家评分</span>
                <div class="pull-right">{{ user.garde }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" style="margin-right:10px;font-size: 16px;"/>
                <span style="font-size:14px;">商家地址</span>
                <div class="pull-right">{{ user.position }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="15" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span style="font-size:18px;font-weight: bold;">基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <!-- <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane> -->
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userInfo from "./userInfo.vue";
import resetPwd from "@/views/system/user/profile/resetPwd";
import { listBusiness, updateBusiness } from "@/api/scancode/business"
import ImageUpload from '@/components/ImageUpload'

export default {
  name: "Profile",
  components: { ImageUpload, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      imageUrl: ''
    };
  },
  created() {
    this.getBusiness();
  },
  methods: {
    getBusiness() {
      listBusiness().then(response => {
        this.user = response.rows[0];
        console.log(this.user)
      });
    },
    uploadAvatar(ossId) {
      this.user.image = ossId
      if (ossId) {
        updateBusiness(this.user).then(() => {
          this.$message.success('修改成功')
        })
      } else {
        updateBusiness(this.user).then(() => {
          this.$message.success('删除成功')
        })
      }
    }
  }
};
</script>
<style scoped>
 .avatar-uploader .el-upload {
    border: 5px dashed #ff6666;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
